name: Scala CI with sbt

on:
  push:
    branches: [ main, master ]
  pull_request:
    branches: [ main, master ]

jobs:
  build-and-publish:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Set up JDK 11
      uses: actions/setup-java@v1
      with:
        java-version: 11

    - name: Cache sbt dependencies
      uses: actions/cache@v2
      with:
        path: |
          ~/.ivy2/cache
          ~/.sbt
          ~/.m2
        key: ${{{openbrackets}}} runner.os {{{closebrackets}}}-sbt-${{{openbrackets}}} hashFiles('**/*.sbt') {{{closebrackets}}}
        restore-keys: |
          ${{{openbrackets}}} runner.os {{{closebrackets}}}-sbt-

    - name: Build with sbt
      run: sbt clean compile test

    - name: Publish to GitHub Packages
      run: sbt publish
      env:
        GITHUB_TOKEN: ${{{openbrackets}}} secrets.GITHUB_TOKEN {{{closebrackets}}}
